﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


namespace FAP.DataAccess.BLL
{
    public class baiviet
    {
        public int id { get; set; }
        public int idtaikhoan { get; set; }
        public int websiteId { get; set; }
        public string tieude { get; set; }
        public string noidung { get; set; }
        public string link { get; set; }
        public DateTime ngaytao { get; set; }
        public bool isdeleted { get; set; }
        //public taikhoan taikhoan { get { return taikhoan.taikhoanSelectRow(idtaikhoan); } }
        //public website website { get { return website.websiteSelectRow(websiteId); } }
        //public List<comment> comments { get { return comment.commentSelectRowByForeignKey_idbaiviet(id); } }

        #region baivietSelectAll
        public static List<baiviet> baivietSelectAll()
        {
            IDataReader dr = FAP.DataAccess.DAL.baivietSelectAll();
            List<baiviet> baivietList = new List<baiviet>();
            while (dr.Read())
            {
                baiviet mybaiviet = new baiviet
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    websiteId = !dr.IsDBNull(dr.GetOrdinal("websiteId")) ? (int)dr["websiteId"] : 0,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                baivietList.Add(mybaiviet);
            }
            dr.Close();
            dr.Dispose();
            return baivietList;
        }
        #endregion

        #region baivietSelectRow
        public static baiviet baivietSelectRow(int id)
        {
            IDataReader dr = FAP.DataAccess.DAL.baivietSelectRow(id);
            baiviet baiviet = null;

            if (dr.Read())
            {
                baiviet = new baiviet
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    websiteId = !dr.IsDBNull(dr.GetOrdinal("websiteId")) ? (int)dr["websiteId"] : 0,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,

                };
            }
            dr.Close();
            dr.Dispose();
            return baiviet;
        }
        #endregion

        #region baivietSelectRowByForeignKey_idtaikhoan
        public static List<baiviet> baivietSelectRowByForeignKey_idtaikhoan(int idtaikhoan)
        {
            IDataReader dr = FAP.DataAccess.DAL.baivietSelectRowByForeignKey_idtaikhoan(idtaikhoan);
            List<baiviet> baivietList = new List<baiviet>();
            while (dr.Read())
            {
                baiviet mybaiviet = new baiviet
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    websiteId = !dr.IsDBNull(dr.GetOrdinal("websiteId")) ? (int)dr["websiteId"] : 0,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                baivietList.Add(mybaiviet);
            }
            dr.Close();
            dr.Dispose();
            return baivietList;
        }
        #endregion

        #region baivietSelectRowByForeignKey_websiteId
        public static List<baiviet> baivietSelectRowByForeignKey_websiteId(int websiteId)
        {
            IDataReader dr = FAP.DataAccess.DAL.baivietSelectRowByForeignKey_websiteId(websiteId);
            List<baiviet> baivietList = new List<baiviet>();
            while (dr.Read())
            {
                baiviet mybaiviet = new baiviet
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    websiteId = !dr.IsDBNull(dr.GetOrdinal("websiteId")) ? (int)dr["websiteId"] : 0,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                baivietList.Add(mybaiviet);
            }
            dr.Close();
            dr.Dispose();
            return baivietList;
        }
        #endregion

        #region baivietSelectRowByForeignKey_idtaikhoan_websiteId
        public static List<baiviet> baivietSelectRowByForeignKey_idtaikhoan_websiteId(int idtaikhoan, int website)
        {
            IDataReader dr = FAP.DataAccess.DAL.baivietSelectRowByForeignKey_idtaikhoan_websiteId(idtaikhoan, website);
            List<baiviet> baivietList = new List<baiviet>();
            while (dr.Read())
            {
                baiviet mybaiviet = new baiviet
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    websiteId = !dr.IsDBNull(dr.GetOrdinal("websiteId")) ? (int)dr["websiteId"] : 0,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,
                };
                baivietList.Add(mybaiviet);
            }
            dr.Close();
            dr.Dispose();
            return baivietList;
        }
        #endregion

        #region baivietInsertRow
        public static void baivietInsertRow(int idtaikhoan, int websiteId, string tieude, string noidung, string link, DateTime ngaytao, bool isdeleted)
        {
            FAP.DataAccess.DAL.baivietInsertRow(idtaikhoan, websiteId, tieude, noidung, link, ngaytao, isdeleted);
        }
        #endregion

        #region baivietUpdateRow
        public static void baivietUpdateRow(int id, int idtaikhoan, int websiteId, string tieude, string noidung, string link, DateTime ngaytao, bool isdeleted)
        {
            FAP.DataAccess.DAL.baivietUpdateRow(id, idtaikhoan, websiteId, tieude, noidung, link, ngaytao, isdeleted);
        }
        #endregion

        #region baivietDeleteRow
        public static void baivietDeleteRow(int id)
        {
            FAP.DataAccess.DAL.baivietDeleteRow(id);
        }
        #endregion
    }
}